<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        div {
            position: absolute;

            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div></div>

    <script>
        // 获取div
        var div = document.querySelector('div');
        // 在文档中移动鼠标，给文档绑定事件监听
        document.addEventListener('mousemove', function (e) {
            // 获取移动的文档中鼠标坐标
            // 把坐标赋值给图片的距离文档左右的值
            var x = e.pageX;
            var y = e.pageY;
            div.style.left = x - 100 + 'px';
            div.style.top = y - 100 + 'px';

        });
    </script>
</body>

</html>